package contratosonline.ejb.controller;

import java.sql.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import contratosonline.entity.VigenciaContratos;

@Stateless
public class VigenciaContratoJPAController implements VigenciaContratoJPAControllerLocal{
	@PersistenceContext
	private EntityManager em;

	public EntityManager getEntityManager() {
		return em;
	}	
    public VigenciaContratoJPAController() {
    	
    }

    /* (non-Javadoc)
	 * @see contratosonline.ejb.controller.VigenciaContratoJPAControllerLocal#findVigenciaContratoAll()
	 */
    @SuppressWarnings("unchecked")
	public List<VigenciaContratos> findVigenciaContratoAll(){
    	EntityManager em = getEntityManager();
        try {
        	Query q = em.createNamedQuery("VigenciaContratos.findAll");
            if (q!=null) {
            	return q.getResultList();  
            }
            return null;
        } finally {
            //em.close();
        }
    }
    
  
    /* (non-Javadoc)
	 * @see contratosonline.ejb.controller.VigenciaContratoJPAControllerLocal#findVigenciaContratoNoPeriodo(java.sql.Date, java.sql.Date)
	 */
    @SuppressWarnings("unchecked")
	public List<VigenciaContratos> findVigenciaContratoNoPeriodo(Date dataInicio, Date dataFim){
    	EntityManager em = getEntityManager();
    	String nomeCampus = "";
		Query q = em.createQuery("select object(o) from Campus as o where o.nomeCampus = '"+nomeCampus +"'");
		if (q!=null) {
			return q.getResultList();
		}
    	return null;
    }
    

}

